package main

func main() {
	a, b := false, true
	if a && b != true {
		println("(a && b) != true")
		return
	} else {
		println("a && (b != true) == false")
	}

	// 更适合多路分支执行的分支控制结构--switch
	switch switchexpr() {
	case case1():
		println("exec case1")
		fallthrough
	case case2():
		println("exec case 2")
		// fallthrough
	default:
		println("exec default")
	}

	var x interface{} = 13
	switch v := x.(type) { // switch 关键字后面跟着的表达式为x.(type)，这种表达式形式市switch语句特有的，而且也只能在switch语句中使用。这个表达式中的x必须是一个借口类型变量, 表达式的求值结果是这个接口类型对应的动态类型
	// v存储的是变量x的动态类型对应的值信息
	case nil:
		println("x is nil")
	case int:
		println("the type of x is int, v = ", v)
	case string:
		println("the type of x is string, v = ", v)
	case bool:
		println("the type of x is bool, v = ", v)
	default:
		println("don't support the type")
	}
}

func case1() int {
	println("eval case1 expr")
	return 1
}

func case2() int {
	println("eval case2 expr")
	return 2
}

func switchexpr() int {
	println("eval switch expr")
	return 1
}

func readByExt(ext string) {
	if ext == "json" {
		println("read json file")
	} else if ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" {
		println("read image file")
	} else if ext == "yml" || ext == "yaml" {
		println("read yaml file")
	} else if ext == "txt" || ext == "md" {
		println("read text file")
	} else if ext == "ini" {
		println("read ini file")
	} else {
		println("unsipported file extensions:", ext)
	}
}

func readByExtBySwitch(ext string) {
	switch ext {
	case "json":
		println("read json file")
	case "jpg", "jpeg", "png", "gif":
		println("read image file")
	case "txt", "md":
		println("read text file")
	case "yml", "yaml":
		println("read yaml file")
	case "ini":
		println("read ini file")
	default:
		println("unsupported file extension:", ext)
	}
}
